package com.example.guiguiapplicatio.fragment.followup.adapter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.guiguiapplicatio.R;
import com.example.guiguiapplicatio.databinding.FragmentClassifyRecyItemBinding;

import java.util.List;

public class FollowUpRecordClassifyFragmentAdapter extends RecyclerView.Adapter<FollowUpRecordClassifyFragmentAdapter.ViewHolder>{
    private List<String> mClassifications;
    private String idcard=null;
    private NavController navController;
    public FollowUpRecordClassifyFragmentAdapter(List<String> mClassifications,String idcard){
        this.mClassifications=mClassifications;
        this.idcard=idcard;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        navController= Navigation.findNavController(parent);
        return new ViewHolder(FragmentClassifyRecyItemBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        final int mPosition = position;
        holder.mClassifications = mClassifications;
        holder.binding.text.setText(mClassifications.get(position));
        if (mClassifications.get(mPosition).equals("新生儿")) {
            holder.binding.image.setImageResource(R.drawable.ertong);
        } else if (mClassifications.get(mPosition).equals("老年人")) {
            holder.binding.image.setImageResource(R.drawable.laonianren);
        } else if (mClassifications.get(mPosition).equals("肺结核")) {
            holder.binding.image.setImageResource(R.drawable.feijiehe);
        } else if (mClassifications.get(mPosition).equals("严重精神障碍")) {
            holder.binding.image.setImageResource(R.drawable.jinshenzhangai);
        } else if (mClassifications.get(mPosition).equals("类风湿关节炎")) {
            holder.binding.image.setImageResource(R.drawable.leifengshiguanjieyan);
        } else if (mClassifications.get(mPosition).equals("脑血管疾病后遗症")) {
            holder.binding.image.setImageResource(R.drawable.naoxueguanhouyizheng);
        } else if (mClassifications.get(mPosition).equals("高血压")) {
            holder.binding.image.setImageResource(R.drawable.gaoxueya);
        }
        holder.binding.recyItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle =new Bundle();
                bundle.putString("type",mClassifications.get(mPosition));
                bundle.putString("idcard",idcard);
                navController.navigate(R.id.action_followUpRecordClassifyFragment_to_followUpReportFragment,bundle);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mClassifications.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        List<String> mClassifications;
        FragmentClassifyRecyItemBinding binding;
        public ViewHolder(@NonNull FragmentClassifyRecyItemBinding binding) {
            super(binding.getRoot());
            this.binding=binding;
        }
    }
}
